package com.ziroom.zifamily.bussiness.common.result;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

/**
 * <p>
 * <PRE>
 * <BR>    修改记录
 * <BR>-----------------------------------------------
 * <BR>    修改日期         修改人          修改内容
 * </PRE>
 *
 * @author cuiyh9
 * @version 1.0
 * @Date Created in 2018年11月24日 16:09
 * @since 1.0
 */
@Builder
@Data
@AllArgsConstructor
public  class Result {


    private String code;

    private String message;

    private String detail;

    private Object data;

    private Result() {

    }


    /**
     * 成功
     * @author cuiyuhui
     * @created
     * @param
     * @return
     */
    public static Result ok() {
        return ok(ResultCodeEnum.SUCCESS.getMessage(), null, null);
    }

    /**
     * 成功
     * @author cuiyuhui
     * @created
     * @param
     * @return
     */
    public static Result ok(Object data) {
        return ok(ResultCodeEnum.SUCCESS.getMessage(), null, data);
    }



    /**
     * 成功
     * @author cuiyuhui
     * @created
     * @param
     * @return
     */
    public static Result ok(String message, String detail, Object data) {
        return Result.builder().code(ResultCodeEnum.SUCCESS.getCode())
                .message(message).detail(detail)
                .data(data).build();
    }


    public static Result fail() {
        return fail(null, null);
    }

    public static Result fail(String message, String detail) {
        return fail(ResultCodeEnum.FAIL.getCode(), message, detail);
    }

    /**
     * 失败 - 自定义code message detail
     * @author cuiyuhui
     * @created
     * @param
     * @return
     */
    public static Result fail(String code, String message, String detail) {
        return Result.builder().code(code).message(message).detail(detail).build();
    }

    /**
     * 参数为空
     * @author cuiyuhui
     * @created
     * @param
     * @return
     */
    public static Result failParamNull() {
        return fail(ResultCodeEnum.FAIL_PARAM_NULL.getCode(), ResultCodeEnum.FAIL_PARAM_NULL.getMessage(), null);
    }

    /**
     * 系统内部错误
     * @author cuiyuhui
     * @created
     * @param
     * @return
     */
    public static Result failSystemError() {
        return failSystemError(ResultCodeEnum.FAIL_SYSTEM_ERROR.getMessage());
    }

    /**
     * 系统内部错误
     * @author cuiyuhui
     * @created
     * @param
     * @return
     */
    public static Result failSystemError(String message) {
        return fail(ResultCodeEnum.FAIL_SYSTEM_ERROR.getCode(), message, null);
    }

    /**
     * Result返回结果统一
     * @author cuiyh9
     */
    public enum ResultCodeEnum {

        /** 操作成功 */
        SUCCESS("0", "操作成功"),
        /** 操作失败 */
        FAIL("-1", "操作失败"),
        /** 参数为空 */
        FAIL_PARAM_NULL("-2", "参数为空"),
        /** 系统错误，内部异常 */
        FAIL_SYSTEM_ERROR("-3", "系统错误，内部异常"),;

        String code;

        String message;


        ResultCodeEnum(String code, String message) {
            this.code = code;
            this.message = message;
        }

        public String getCode() {
            return this.code;
        }

        public String getMessage() {
            return this.message;
        }

    }


}
